package com.zyj.exam_app.testPaper_manager.controller;

import com.zyj.exam_app.testPaper_manager.bean.TestPaperBean;
import com.zyj.exam_app.testPaper_manager.service.TestPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 试卷管理Controller
 */
@Controller
@RequestMapping("/testPaperManager")
public class TestPaperManagerController {

    @Autowired
    private TestPaperService testPaperService;

    @RequestMapping("/testPaperList")
    public String testPaperListPage(Model model){
        List<TestPaperBean> testPaperList = testPaperService.findAllTestPapers();
        model.addAttribute("testPaperList", testPaperList);

        return "testpaper/list";
    }


    @RequestMapping("/addPage")
    public String testPaperAddPage(){
        return "testpaper/add";
    }

    @PostMapping("/addOneTestPaper")
    @ResponseBody
    public String addOneTestPaper(@RequestBody TestPaperBean testPaper){
        testPaperService.addOneTestPaper(testPaper);
        return "OK";
    }

    @GetMapping("/deleteOneTestPaper/{testPaperId}")
    public String deleteOneTestPaper(@PathVariable("testPaperId") String testPaperId){
        testPaperService.deleteOneTestPaperById(testPaperId);
        return "forward:/testPaperManager/testPaperList";
    }

}
